package com.sskj.xgja.transaction;

import com.sskj.xgja.BasePresenter;
import com.sskj.xgja.api.ApiObserver;
import com.sskj.base.utils.RxUtils;
import com.sskj.xgja.api.Api;
import com.sskj.xgja.market.bean.MarketData;

import java.util.List;


/**
 * @author Hey
 * Create at  2019/03/20
 */
class BuyInPresenter extends BasePresenter<BuyInFragment> {

    public void placeOrder(String action, String entrustCount, String price, String stockCode, String billType) {
        Api.getInstance().placeOrder(action, entrustCount, price, stockCode, billType)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<Object>(this, true) {
                    @Override
                    public void onSuccess(Object data) {
                        mView.placeOrderSuccess();
                    }
                });
    }

    // 根据用户所选币种进行行情详细币种请求
    public void getMarketDetail(String code, boolean showLoading) {
        Api.getInstance().marketDetail(code)
                .compose(RxUtils.transform())
                .subscribe(new ApiObserver<List<MarketData>>(this, showLoading) {
                    @Override
                    public void onSuccess(List<MarketData> data) {
                        mView.setMarketDetail(data.get(0));
                    }
                });
    }

}
